﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<QianBuo.Lottery.Web.Models.Play.PlayTypeModel>" %>
<%@ Import Namespace="Code.Models" %>
<div style="width: 618px; ">
    <div id="play_inputpanel">
        <%
            var zusan = (PlayType_E)ViewData["ZuSan"];
            var zuliu = (PlayType_E)ViewData["ZuLiu"];    
        %>
        <table border="0" cellpadding="0" cellspacing="5" class="play_play_input" align="center">
            <tr id="input_model">
                <td width="60px">
                    &nbsp;
                </td>
                <td colspan="17" align="left">
                    <input type="radio" name="inputtype" class='type<%=(int)zusan %>'  id='组三' value='<%=(int)zusan %>'  /><label for='组三'>组三(复式-鼠标)</label>
                    <input type="radio" name="inputtype" class='type<%=(int)zuliu %>' id='组六' value='<%=(int)zuliu %>'  /><label for='组六'>组六(复式-鼠标)</label>
                    <input type="radio" name="inputtype" class="type-1" value='-1' id="混合" /><label for="混合">混合组选(单式-键盘)</label>
                </td>
            </tr>
            <tr class="tr_number" id='input_<%=(int)zusan %>'>
                <td class="head">组三</td>
                <td class="number">0</td>
                <td class="number">1</td>
                <td class="number">2</td>
                <td class="number">3</td>
                <td class="number">4</td>
                <td class="number">5</td>
                <td class="number">6</td>
                <td class="number">7</td>
                <td class="number">8</td>
                <td class="number">9</td>
                <td>&nbsp;</td>
                <td class="tool">全</td>
                <td class="tool">大</td>
                <td class="tool">小</td>
                <td class="tool">奇</td>
                <td class="tool">偶</td>
                <td class="tool">清</td>
            </tr>
            <tr class="tr_number" id='input_<%=(int)zuliu %>'>
                <td class="head">组六</td>
                <td class="number">0</td>
                <td class="number">1</td>
                <td class="number">2</td>
                <td class="number">3</td>
                <td class="number">4</td>
                <td class="number">5</td>
                <td class="number">6</td>
                <td class="number">7</td>
                <td class="number">8</td>
                <td class="number">9</td>
                <td>&nbsp;</td>
                <td class="tool">全</td>
                <td class="tool">大</td>
                <td class="tool">小</td>
                <td class="tool">奇</td>
                <td class="tool">偶</td>
                <td class="tool">清</td>
            </tr>
            <tr class="tr_number" id="input_-1">
                <td colspan="18" height="120px">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%">
                        <tr>
                            <td align="center">
                                <font color="red" size="-1">请在下方的输入框内输入或粘贴投注内容，每注请使用 逗号、空格或 ";" 分割开</font>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <textarea id="input_keybord" class="input_keybord"></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr id="playinfo">
                <td colspan="18" style="text-align:left">
                    <%=Model.Remark %>
                </td>
            </tr>
            <tr>
                <td colspan="8" id="sumcount">
                    注数:<font color="red">0</font>
                </td>
                <td colspan="10" align="left">
                    <input type="button" name="bet_play_btnadd" onclick="ZuXuan.addScheme()" id="bet_play_btnadd"
                        value="添加" class="bet_play_btnadd" />
                </td>
            </tr>
        </table>
    
        <script type="text/javascript">
            var __playid=<%=Model.PlayID %>;
            $(document).ready(showWinInfo);
            function showWinInfo(){
                var pwin = Site.Lottery.Bet.GetPlayTypeWinMoney(function(item){ return item.PlayTypeID == __playid;});
                if(pwin != null)
                    $('<span><%=string.IsNullOrEmpty(Model.Remark) ? "" : "，" %>'+"奖金:<font color='red'>"+pwin.WinMoney+"元</font></span>").appendTo($("#playinfo td"));
                else
                    window.setTimeout(showWinInfo,500);
            }

            $(".play_play_input .number").click(function() {
                var item = $(this);
                var id = item.parent().find('.head').text();
                if (item.is(".select")) {
                    item.removeClass("select");
                    ZuXuan.PlayModels[id].Numbers = ZuXuan.PlayModels[id].Numbers.replace(item.text(), '');
                } else {
                    item.addClass("select");
                    ZuXuan.PlayModels[id].Numbers = ZuXuan.PlayModels[id].Numbers + item.text();
                }
                var count = 0;
                if (id == '组三') {
                    count = ZuXuan.PlayModels[id].Numbers.length * (ZuXuan.PlayModels[id].Numbers.length - 1);
                } else if (id == '组六') {
                    count = ZuXuan.ZuLiuCount[ZuXuan.PlayModels[id].Numbers.length];
                }
                $(".play_play_input #sumcount font").html(count);
            });

            ZuXuan={};

            $(".play_play_input .tool").click(function () {
                ZuXuan.selectNumber($(this).parent().find(".number"), this.innerText);
            });

            ZuXuan.PlayModels=[];
            ZuXuan.PlayModels['组三'] = {ID:<%=(int)ViewData["ZuSan"] %>,Name:'<%=((PlayType_E)ViewData["ZuSan"]).GetName() %>',Numbers:''};
            ZuXuan.PlayModels['组六'] = {ID:<%=(int)ViewData["ZuLiu"] %>,Name:'<%=((PlayType_E)ViewData["ZuLiu"]).GetName() %>',Numbers:''};
            ZuXuan.PlayModels['混合'] = {ID:-1,Name:'混合组选',Numbers:''};

            ZuXuan.PlayID=<%=Model.ID %>;
            ZuXuan.PlayName='<%=Model.Name%>';

            ZuXuan.SetCurrentPlay = function(id, name) {
                ZuXuan.PlayID = id;
                ZuXuan.PlayName = name;

                Site.Lottery.Bet.SetCurrentPlay(ZuXuan.PlayID, ZuXuan.PlayName);
            };
            
            ZuXuan.ZuLiuCount = [0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120];
            ZuXuan.addScheme = function() {
                var id = null;
                var number = null;
                var count = 0;
                if (ZuXuan.PlayID == ZuXuan.PlayModels['组三'].ID) {
                    id = "组三";
                    number = ZuXuan.PlayModels[id].Numbers.split('').sort().join('');
                    count = number.length * (number.length - 1);
                } else if (ZuXuan.PlayID == ZuXuan.PlayModels['组六'].ID) {
                    id = "组六";
                    number = ZuXuan.PlayModels[id].Numbers.split('').sort().join('');
                    count = ZuXuan.ZuLiuCount[number.length];
                } else {
                    id = "混合";
                    var number1 = $(".play_play_input #input_-1 .input_keybord").val();
                    var valid = /^[ \r\n\t,;\d]{1,}$/;
                    if (!valid.test(number1)) {
                        alert('请不要输入除数字、逗号、回车、空格或 ";"以外的字符');
                        return;
                    }
                    var reg = /[ \r\n\t,;]/;
                    var temp = number1.split(reg);
                    var number = new Array();

                    for (var n in temp) {
                        if (temp[n] == null || temp[n].length != 3) {
                            continue;
                        }
                        var play = null;
                        var t1 = temp[n].split("");
                        if (t1[0] == t1[1] && t1[0] == t1[2]) {
                            continue;
                        } else if (t1[0] != t1[1] && t1[0] != t1[2] && t1[1] != t1[2]) { //组六
                            play = ZuXuan.PlayModels['组六'];
                        } else { //组三
                            play = ZuXuan.PlayModels['组三'];
                        }
                        count++;
                        number.push({ playid: play.ID, playname: play.Name, number: t1.join(""), count: 1, args: 0 });
                    }
                    ZuXuan.PlayModels[id].Numbers = number;
                }

                if (count < 1) {
                    alert('号码选择不正确！');
                    return;
                }
                if (id == "混合") {
                    Site.Lottery.Bet.AddPlayItems(ZuXuan.PlayModels[id].Numbers);

                    $(".play_play_input #input_-1 .input_keybord").val('');
                } else {
                    if (Site.Lottery.Bet)
                        Site.Lottery.Bet.AddPlayItem(ZuXuan.PlayID, ZuXuan.PlayName, number, count, 1);

                    ZuXuan.PlayModels[id].Numbers = '';
                    $(".play_play_input #sumcount font").html('0');
                    $(".play_play_input #input_" + ZuXuan.PlayID + " .tool:contains('清')").click();
                }
            };

            ZuXuan.selectNumber = function(numbers, type) {
                numbers.each(function() {
                    $(this).removeClass("select");
                });
                ZuXuan.PlayModels[numbers.parent().find('.head').text()].Numbers = '';
                $(".play_play_input #sumcount font").html('0');

                switch (type) {
                case "全":
                    numbers.click();
                    break;
                case "大":
                    numbers.each(function() {
                        if (parseInt(this.innerText) > 4)
                            $(this).click();
                    });
                    break;
                case "小":
                    numbers.each(function() {
                        if (parseInt(this.innerText) < 5)
                            $(this).click();
                    });
                    break;
                case "奇":
                    numbers.each(function() {
                        if (parseInt(this.innerText) % 2 == 1)
                            $(this).click();
                    });
                    break;
                case "偶":
                    numbers.each(function() {
                        if (parseInt(this.innerText) % 2 == 0)
                            $(this).click();
                    });
                    break;
                }
            };

            ZuXuan.InputModel_click = function() {
            };


            $(".play_play_input .tr_number").each(function () {
                if (this.id != 'input_' + ZuXuan.PlayID)
                    $(this).hide();
            });
            var isSingle=<%="true".Equals(TempData["singleplay"] as string)?"true":"false" %>;
            
            $("#input_model :radio").each(function () {
                var item = $(this);
                var val=parseInt(this.value);
                item.click(function () {
                    $(".play_play_input .input_show").removeClass("input_show").hide();
                    $(".play_play_input #input_" + this.value).addClass("input_show").show();
                    var play = ZuXuan.PlayModels[this.id];
                    if (this.value == -1) {
                        $(".play_play_input #sumcount font").html('0'); 
                        ZuXuan.SetCurrentPlay( play.ID,play.Name);
                    } else{
                        $(".play_play_input #input_"+this.value+" .number:first").click().click();

                        if (ZuXuan.PlayID == val) {
                            ZuXuan.SetCurrentPlay( play.ID,play.Name);
                            return;
                        }
                        if(isSingle){
                            location.href=item.attr('surl');
                            return;
                        }
                        var url='<%=Url.Action("Play",new {p1="!"}) %>/'.replace("!",val);
                        $("#play_bet_bar").block({ message: "<img src='<%=Url.Content("~/Content/images/busy.gif") %>'/>载入中..." ,css:{cursor:"default"},overlayCSS:{cursor:"default"}});
                        $("#play_bet_bar").load(url, null, function (p, e, i) {
                            $("#play_bet_bar").unblock();
                            if (e == 'success' && $(p).has("#play_inputpanel")) {
                            } else {
                                $("#input_model .type" + val).click();
                                return false;
                            }
                        });
                    }
                });
                if(ZuXuan.PlayID == parseInt(item.val()))
                    this.checked = true;
            });
            $("#input_model :radio:checked").click();

        </script>
    </div>
</div>